using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace WorkFlow.Utils
{
    [RequireComponent(typeof(ToggleDo))]
    [AddComponentMenu("WorkFlow/Utils/ToggleDo")]
    public class ToggleDo : MonoBehaviour
    {
        [SerializeField] GameObject[] targetObjects;
        [SerializeField] bool negation = false;
        Toggle _toggle;

        private void Awake()
        {
            _toggle = gameObject.GetComponent<Toggle>();
            _toggle.onValueChanged.AddListener(DoSomething);
        }

        private void DoSomething(bool active)
        {
            foreach (var item in targetObjects)
            {
                if(negation)
                    item.SetActive(!active);
                else
                    item.SetActive(active);
            }
        }
        
#if UNITY_EDITOR
        private void Reset()
        {
            _toggle = gameObject.GetComponent<Toggle>();
        }
#endif
    }
}
